// SplitPanel.cpp: implementation of the SplitPanel class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SplitPanel.h"
#include "SplitPanelPeer.h"
#include "SplitterPane.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SplitPanel::SplitPanel(int orient)
{
	m_orient = orient;

	m_panel1 = new AWTPanel();
	m_panel2 = new AWTPanel();
	m_panel1->setLayout(new AWTBorderLayout());
	m_panel2->setLayout(new AWTBorderLayout());

	add(m_panel1);
	add(m_panel2);
}

SplitPanel::~SplitPanel()
{

}

CWnd* SplitPanel::createComponent()
{
	CWnd* wParent = getParent()->getPeer();
	if (wParent == NULL)
		return NULL;
	SplitPanelPeer* pwnd = new SplitPanelPeer(this);	 

//	CRect rc;
//	m_pane1.Create(NULL, "", WS_CHILD | WS_VISIBLE, rc, pwnd, 0);
//	m_pane2.Create(NULL, "", WS_CHILD | WS_VISIBLE, rc, pwnd, 0);

	int rows = m_orient == horz ? 1 : 2;
	int cols = m_orient == vert ? 1 : 2;

	pwnd->CreateStatic(wParent, rows, cols, WS_CHILD | WS_VISIBLE);

	SplitterPane* pane1;
	SplitterPane* pane2;
	if (m_orient == horz)
	{
		pwnd->CreateView(0,0, RUNTIME_CLASS(SplitterPane), m_panel1->getComponent(0)->getSize(), NULL);
		pwnd->CreateView(0,1, RUNTIME_CLASS(SplitterPane), m_panel2->getComponent(0)->getSize(), NULL);
		pane1 = (SplitterPane*)pwnd->GetPane(0,0);
		pane2 = (SplitterPane*)pwnd->GetPane(0,1);
	}
	else
	{
		pwnd->CreateView(0,0, RUNTIME_CLASS(SplitterPane), m_panel1->getComponent(0)->getSize(), NULL);
		pwnd->CreateView(1,0, RUNTIME_CLASS(SplitterPane), m_panel2->getComponent(0)->getSize(), NULL);
		pane1 = (SplitterPane*)pwnd->GetPane(0,0);
		pane2 = (SplitterPane*)pwnd->GetPane(1,0);
	}

	pane1->m_comp = m_panel1;
	pane2->m_comp = m_panel2;

	m_panel1->setPeer(pane1);
	m_panel2->setPeer(pane2);

//	pwnd->MoveWindow(getBounds());

	return pwnd;
}

/*
void SplitPanel::addNotify()
{
	if (m_peer == NULL)
		m_peer = createComponent();
	invalidate();

	AWTComponent* cmp1 = getComponent(0);
	AWTComponent* cmp2 = getComponent(1);

	m_pane = 1;
	cmp1->addNotify();
	m_pane = 2;
	cmp2->addNotify();
}

CWnd* SplitPanel::getPeer()
{
	if (m_peer == NULL)
		return NULL;
	SplitPanelPeer* peer = (SplitPanelPeer*) m_peer;

	if (m_pane == 1)
	{	
		return peer->GetPane(0, 0);
	}
	else
	{
		if (m_orient == horz)
			return peer->GetPane(0, 1);
		else
			return peer->GetPane(1, 0);
	}
	return NULL;
}
*/

